package org.dut.ioc;

import org.dut.ioc.Controller.UController;
import org.dut.ioc.Controller.UserController;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

//Spring扫描的路径，扫描到的Bean才会生效
//@ComponentScan({"org.dut.ioc.v2"})
@SpringBootApplication
public class IocApplication {

    public static void main(String[] args) {
        //获取上下文，保存在context中
        ApplicationContext context = SpringApplication.run(IocApplication.class, args);
        //3种获取Bean的方式，Bean名是首字母小写的小驼峰
        UserController controller = (UserController) context.getBean("userController");
        controller.hello();
//        UserController controller2 = context.getBean("userController", UserController.class);
//        controller2.hello();
//        UserController controller3 = context.getBean(UserController.class);
//        controller3.hello();

        //前两个字母大写的Bean，Bean名是本身
        UController controller5 = (UController) context.getBean("UUC");
        controller5.hello();

        User user = (User) context.getBean("u1");
        System.out.println(user);

    }

}
